module game{
    export class GameOverView extends BaseEuiView{
        public btn_back:eui.Button;
        public btn_share:eui.Button;
        // public btn_showOff:eui.Button;
        // public btn_TV:eui.Button;
        public tv:eui.Image;
        public share:eui.Image;
        public xuanyao:eui.Image;

        public txt_score:eui.Label;
        public txt_time:eui.Label;
        public txt_next:eui.Label;
        
        private time = 10;
        public constructor($m:BaseController,$parent:eui.Group){
            super($m,$parent);
            this.skinName = "resource/skin/GameOver.exml";
        }

        public initUI():void{
            super.initUI();

            const self = this;
            this.btn_back.addEventListener(egret.TouchEvent.TOUCH_TAP,this.backHomeHandler,this);
            this.txt_next.addEventListener(egret.TouchEvent.TOUCH_TAP,this.nextHandler,this);

            this.skin.width = egret.MainContext.instance.stage.stageWidth;
            this.skin.height = egret.MainContext.instance.stage.stageHeight;
        }

        public open(...param:any[]):void {
            super.open(...param);

            this.txt_score.text = gameData.curmax +"";

            this.time = 10;
            this.txt_time.text = this.time+"";
            this.txt_next.visible = false;

            this.tv.visible = false;
            this.share.visible = false;
            this.xuanyao.visible = false
            if(gameData.reviveCount == 2){
                //第一次复活
                //合规
                this.xuanyao.visible = true;
            }else if(gameData.reviveCount == 1){
                this.tv.visible = true;
            }

            App.TimerManager.remove(this.timeUpdate,this);
            App.TimerManager.doTimer(1000,0,this.timeUpdate,this);
        }

        private timeUpdate(){
            this.time --;
            if(this.time == 7){
                this.txt_next.visible = true;
            }
            if(this.time < 0 ){
                this.nextHandler();
                App.TimerManager.remove(this.timeUpdate,this);
                return;
            }
            this.txt_time.text = this.time+"";
        }

        private backHomeHandler(){
            //clearAll
            App.ViewManager.close(ViewConst.Core);
            App.ViewManager.close(ViewConst.GameOver);
            App.ViewManager.open(ViewConst.Home);
            App.TimerManager.remove(this.timeUpdate,this);
        }

        private nextHandler(){
            //跳过
            this.gameResult();
        }

        /**结算面板 */
        private gameResult(){
            App.TimerManager.remove(this.timeUpdate,this);
            App.ViewManager.close(ViewConst.GameOver);
            App.ViewManager.open(ViewConst.GameResult);
        }

        /**复活 */
        private revive(){
            //道具次数充值
            gameData.resetItem();
            gameData.reviveCount--;
            
            App.ViewManager.close(ViewConst.GameOver);
            App.ViewManager.open(ViewConst.Core);
            App.TimerManager.remove(this.timeUpdate,this);
        }
    }
}